package filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter(filterName = "DgutFilter")
public class DgutFilter implements Filter{
    @Override
    public void init(FilterConfig filterConfig) {
    }
    @Override
    public void doFilter (ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        String uri=request.getRequestURI();
        if(request.getParameter("token")==null){
            response.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=" + request.getSession().getId());
        }
        else{
            chain.doFilter(req, resp);
        }
    }
    @Override
    public void destroy() {
    }
}
